Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

533
Visualizações
How to resolve "Did you set the Font Awesome icon font size inside the body of function?" error?

Can someone please tell me why, when I test the code, I get an error that the code has failed even though everything is working properly? I get the same error for all the 4 functions, and the font size is entered. Thanks in advance.

The Error: Did you set the ingredients Font Awesome icon font size inside the body of the ingredientsNormal() function?

<script>
  function ingredientsHover() {
      document.getElementById("ingredients").firstElementChild.firstElementChild.style.fontSize = "300%";
  }

  function ingredientsNormal() {
      document.getElementById("ingredients").firstElementChild.firstElementChild.style.fontSize = "100%";
  }

  function preparationHover() {
      document.getElementById("preparation").firstElementChild.firstElementChild.style.fontSize = "300%";
  }

  function preparationNormal() {
      document.getElementById("preparation").firstElementChild.firstElementChild.style.fontSize = "100%";
  }
</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Could you tell is why the code has failed? What kind of information did you get from the notification?

The browser behaves permissive regarding not correct executed code. He tries doing it's best converting your stuff into usable HTML ^^ That's way you're test may fail but your browser silently accepts it.

My first approach would be to reduce the complexity by only executing one of those functions first and secondly only logging the outcome of a reduced function call like:

function ingredientsHover() {
  const ingredients = document.getElementById("ingredients").firstElementChild;
  console.log("ingredients: ", ingredients);
}

If this works you can expand your approach until you hopefully catch the problematic part.

By the way... Selecting elements the way you're doing it is error prone.

You have several ways to improve your code regarding this. Two possible suggestions:

  1. Make use of optional chaining like: document.getElementById("ingredients")?.firstElementChild?.firstElementChild?.style?.fontSize="300%"
  2. Improve your way of selecting elements like the following psydo code proposes a possible way: document.querySelector('#ingredients:first-child:first-child'); I didn't tested it but you should get the idea right? :-)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda